<?php

use App\Http\Controllers\Admin\AuthController;
use App\Http\Controllers\Admin\Content\ArticleController;
use App\Http\Controllers\Admin\Content\CategoryController;
use App\Http\Controllers\Admin\Content\LinkController;
use App\Http\Controllers\Admin\Content\TagController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\Setting\PermissionController;
use App\Http\Controllers\Admin\Setting\RoleController;
use App\Http\Controllers\Admin\Setting\UserController;
use App\Http\Controllers\Admin\Setting\WebSiteController;
use App\Http\Controllers\Admin\Technical\AccessLogController;
use App\Http\Controllers\Admin\Technical\LogController;
use App\Http\Controllers\Admin\Technical\LoginLogController;
use App\Http\Controllers\Admin\UploadController;
use Illuminate\Support\Facades\Route;


Route::get('/', function () {
    if (auth()->check()) {
        return redirect()->route('admin.dashboard');
    }
    return redirect()->route('admin.login'); // 使用命名路由
});

// 登录页面
Route::get('/login', [AuthController::class, 'login'])->name('login');
Route::post('/authenticate', [AuthController::class, 'authenticate'])->name('authenticate');


//
// 已登录用户
Route::middleware('admin.session.auth')->group(function () {

    Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');
    Route::get('/logout', [AuthController::class, 'logout'])->name('logout');
    Route::get('clear-cache', [AuthController::class, 'clearCache'])->name('clear-cache');

    // 内容
    Route::prefix('content')->name('content.')->group(function () {
        // 文章
        Route::apiResource('articles', ArticleController::class)->names('articles');
        // 分类
        Route::apiResource('article-categories', CategoryController::class)->names('article.categories');
        // 标签
        Route::apiResource('article-tags', TagController::class)->names('article.tags');
//        Route::apiResource('comments', CommentController::class)->names('article.comments');
        // 友情链接
        Route::apiResource('article-links', LinkController::class)->names('article-links');
    });



    // 系统设置
    Route::prefix('setting')->name('setting.')->group(function () {

        Route::get('/website', [WebSiteController::class, 'index'])->name('website.index');
        Route::post('/website', [WebSiteController::class, 'update'])->name('website.update');

        // 用户管理
        Route::apiResource('users', UserController::class)->names('users');
        // 角色管理
        Route::apiResource('roles', RoleController::class)->names('roles');
        // 权限管理
        Route::apiResource('permissions', PermissionController::class)->names('permissions');
    });

    // 技术
    Route::prefix('technical')->name('technical.')->group(function () {
        // 操作日志
        Route::get('/logs', [LogController::class, 'index'])->name('logs.index');
        // 登录日志
        Route::get('/logins', [LoginLogController::class, 'index'])->name('logins.index');
        // 访问日志
        Route::get('/access', [AccessLogController::class, 'index'])->name('access.index');
    });

    // 文件上传
    Route::prefix('upload')->name('upload.')->group(function () {
        Route::post('image', [UploadController::class, 'image'])->name('image');
        Route::post('avatar', [UploadController::class, 'avatar'])->name('avatar');
    });
});

